﻿using System;

namespace DesignModeConsole.设计原则.LiskovSubstitutionPrinciple
{
    /// <summary>
    /// 里式替换原则
    /// </summary>
    public class Service
    {
        public void Test()
        {
            /*
             假设一个企业有三种员工，一种是拿铁饭碗的永久雇员，一种是合同工，一种是临时工。我们设计几个类来表示这三种员工。
             */

            {
                //错误设计
                Employee1 e;
                e = new PermanentEmployee1() { Name = "张三" };
                Console.WriteLine($"{e.Name} 的年终奖是 {e.CalculateBonus()} 元");

                e = new ContractEmployee1() { Name = "李四" };
                Console.WriteLine($"{e.Name} 的年终奖是 {e.CalculateBonus()} 元");

                e = new TemporaryEmployee1() { Name = "王五" };
                Console.WriteLine($"{e.Name} 的年终奖是 {e.CalculateBonus()} 元");//报错
            }

            {
                //正确的设计
                Employee2 e;
                IEmployee2 ie;

                var p = new PermanentEmployee2() { Name = "张三" };
                e = p;
                ie = p;
                Console.WriteLine($"{e.Name} 的年终奖是 {ie.CalculateBonus()} 元");

                var c = new ContractEmployee2() { Name = "李四" };
                e = c;
                ie = c;
                Console.WriteLine($"{e.Name} 的年终奖是 {ie.CalculateBonus()} 元");

                e = new TemporaryEmployee2() { Name = "王五" };
                Console.WriteLine($"{e.Name} 是临时工，无年终奖。");
            }
        }
    }
}